package com.moss.cloud.common.core.enums;

import com.moss.cloud.common.core.model.from.AuthFrom;
import lombok.AllArgsConstructor;
import lombok.Getter;

@Getter
@AllArgsConstructor
public enum GrantTypeEnum {
    /**
     * 授权模式字段标识
     */
    GRANT_TYPE("grant_type","grant_type"),
    /**
     * 客户端授权模式
     */
    CLIENT("client","client_credentials"),
    /**
     * 授权码模式
     */
    CODE("code","authorization_code"),
    /**
     * 账号密码模式
     */
    PASSWORD("password","password"),
    /**
     * 短信费验证码模式
     */
    SMS_CODE("sms_code","sms_code"),
    /**
     * 账号密码加图形验证码模式
     */
    CAPTCHA("captcha","captcha"),
    /**
     * 刷新token模式
     */
    REFRESH("refresh","refresh_token"),
    /**
     *微信小程序模式
     */
    MINI_APP("mini_app","mini_app"),
    /**
     * token字段
     */
    ACCESS_TOKEN("access_token","access_token"),
    /**
     * 过期时间字段
     */
    EXPIRES_IN("expires_in","expires_in"),
    /**
     * 默认的AUTHORIZATION不可修改
     */
    DEF_AUTHORIZATION("AUTHORIZATION","Basic QzBDMzRERjc2ODMwRkE1MkU5NDk0NUY0QkMyMkUxRTg6MTE2OTNEQkNGM0JBQTE0OUI3MEE5QzY4QUFFRjQ5QTA="),
    /**
     * token类型
     */
    TOKEN_TYPE("TOKEN_TYPE","Bearer "),
    ;
    /**
     * code
     */
    private final String type;
    /**
     * 描述
     */
    private final String value;

    public static AuthFrom authFrom(String clientId,String clientSecret){
        AuthFrom authFrom = new AuthFrom();
        authFrom.setGrant_type(GrantTypeEnum.CLIENT.getValue());
        authFrom.setUsername(clientId);
        authFrom.setPassword(clientSecret);
        authFrom.setScope("read");
        return authFrom;
    }
}
